<?php

namespace App\Dao\System;

use Yj\Daos\BaseDaos;
use App\Model\System\SystemConfigClassify;
use Hyperf\Database\Model\Builder;
use Yj\Daos\Verify;
use Hyperf\Utils\Collection;

/**
 * @var SystemConfigClassify
 * @method $this params($params)
 */
class SystemConfigClassifyDao extends BaseDaos
{
    public function searchParams(Collection $params)
    {
        $search = $this->getSearch();
        $params->check('id', function ($id) use ($search) {
            $search->where('id', $id);
        });
        return $search;
    }

    public function lists(Collection $params)
    {
        $data = $this->params($params)->orderByDesc("id")->getList();
        return $data;
    }

    public function add(Collection $params)
    {
        $data = $this->create($params->toArray());
        return $data;
    }


    public function del(int $id)
    {
        $data = $this->DaoWhere(["id" => $id])->firstOrError();
        return $data->delete();
    }

    public function edit(int $id, \App\Tool\Collect|Collection $params)
    {
        $dao = $this->params(_Collect(['id' => $id]))->firstOrError();
        $dao->fill($params->toArray());
        return $dao->save();
    }
}
